package ui.panels.commands;

import ui.panels.strategies.StrategyFrame;
import ui.panels.strategies.manual.ManualPanel;
import gameEngine.agents.choosingStrategy.representation.EGreedyRepresentation;
import gameEngine.agents.choosingStrategy.representation.GreedyRepresentation;
import gameEngine.agents.choosingStrategy.representation.RoundRobinRepresentation;
import gameEngine.agents.choosingStrategy.representation.SelectWorstRepresentation;
import gameEngine.agents.choosingStrategy.representation.SimpleRandomRepresentation;
import gameEngine.agents.choosingStrategy.representation.StrategyRepresentation;
import Data.ConfigurationParameters;

/**
 * 
 * @author vladimir && alon
 *	Check if need to open frame for the strategy
 *		and if does, open it
 *	After that update the strategy in the player properties
 */
public class StrategyFrameCommand implements Command{

	private String 	strategy	= null;
	private int 	gameNumber = 0;
	private int 	playerNumber = 0;
	private int		turnsInGame = 0;
	
	public void execute()
	{
		//check that the params was not forgotten to be set
		if(strategy == null)
		{
			//do nothing
		}
		//case Manual adaptive
		else if(strategy.equals(ConfigurationParameters.Strategy.MANUAL_ADAPTIVE))
		{
			StrategyFrame frame = new StrategyFrame(ConfigurationParameters.Strategy.STRATEGY);
			frame.add(new ManualPanel(frame, gameNumber, playerNumber, turnsInGame));
			//frame.pack();
			frame.repaint();
		}
		//case EGreedy
		else if(strategy.equals(ConfigurationParameters.Strategy.EGREEDY))
		{
			//--- have not parameters , GUI not needed
			
			EGreedyRepresentation eGreedyRepresentation = new EGreedyRepresentation(strategy);
			helpSet(eGreedyRepresentation);
		}
		//case Greedy
		else if(strategy.equals(ConfigurationParameters.Strategy.GREEDY))
		{
			//--- have not parameters , GUI not needed
			
			GreedyRepresentation greedyRepresentation = new GreedyRepresentation(strategy);
			helpSet(greedyRepresentation);
		}

		//case Round Robin
		else if(strategy.equals(ConfigurationParameters.Strategy.ROUND_ROBIN))
		{
			RoundRobinRepresentation roundRobinRepresentation = new RoundRobinRepresentation(strategy);
			helpSet(roundRobinRepresentation);
		}
		//case Select Worst
		else if(strategy.equals(ConfigurationParameters.Strategy.SELECT_WORST))
		{
			SelectWorstRepresentation worstRepresentation = new SelectWorstRepresentation(strategy);
			helpSet(worstRepresentation);
		}
		//case Simple Random
		else if(strategy.equals(ConfigurationParameters.Strategy.SIMPLE_RANDOM))
		{
			SimpleRandomRepresentation simpleRandomRepresentation = new SimpleRandomRepresentation(strategy);
			helpSet(simpleRandomRepresentation);
		}
	}

	public void setStrategy(String strategy) {
		this.strategy = strategy;
	}
	
	
	public void setGameNumber(int gameNumber) {
		this.gameNumber = gameNumber;
	}

	public void setPlayerNumber(int playerNumber) {
		this.playerNumber = playerNumber;
	}

	
	public void setTurnsInGame(int turnsInGame) {
		this.turnsInGame = turnsInGame;
	}

	/**
	 * Design for avoiding duplicate code
	 */
	private void helpSet(StrategyRepresentation representation)
	{
		SetStrategyRepresentationCommand command = new SetStrategyRepresentationCommand();
		command.setStrategyRepresentation(representation);
		command.execute();
	}
	
}
